package com.google.code.ptrends.common.entities;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

public class Item {

    private int id;
    private String itemModel;
    private Date version;
    private ItemCategory category;
    private ItemClass itemClass;
    private Manufacturer manufacturer;

    private Supplier supplier;
    private List<Property> properties;
    private List<Price> prices;

    public Item() {
	properties = new ArrayList<Property>();
	prices = new ArrayList<Price>();
    }

    public void setId(int id) {
	this.id = id;
    }

    public int getId() {
	return id;
    }

    public Supplier getSupplier() {
	return supplier;
    }

    public void setSupplier(final Supplier supplier) {
	this.supplier = supplier;
    }

    public Manufacturer getManufacturer() {
	return manufacturer;
    }

    public void setManufacturer(final Manufacturer manufacturer) {
	this.manufacturer = manufacturer;
    }

    public String getItemModel() {
	return itemModel;
    }

    public void setItemModel(final String itemModel) {
	this.itemModel = itemModel;
    }

    public ItemCategory getCategory() {
	return category;
    }

    public void setCategory(final ItemCategory category) {
	this.category = category;
    }

    public ItemClass getItemClass() {
	return itemClass;
    }

    public void setItemClass(final ItemClass itemClass) {
	this.itemClass = itemClass;
    }

    public List<Property> getProperties() {
	return properties;
    }

    public void setProperties(final Collection<Property> properties) {
	this.properties = new ArrayList<Property>(properties);
    }

    public List<Price> getPrices() {
	return prices;
    }

    public void setPrices(final Collection<Price> prices) {
	this.prices = new ArrayList<Price>(prices);
    }

    public Date getVersion() {
	return version == null ? null : new Date(version.getTime());
    }

    public void setVersion(final Date version) {
	this.version = version == null ? null : new Date(version.getTime());
    }

    public Price getPrice(Date date) {
	Price priceRes = null;
	for (Price price : prices) {
	    if (price.getDate().equals(date)) {
		priceRes = price;
		break;
	    }
	}
	return priceRes;
    }

    public Property getProperty(String name) {
	Property propertyRes = null;

	for (Property property : properties) {
	    if (property.getName().equals(name)) {
		propertyRes = property;
		break;
	    }
	}

	return propertyRes;
    }
}
